﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DAL;

namespace BLL
{
    public class BDriver
    {

        private readonly DAL.DDriver _dDriver = new DDriver();
        /// <summary>
        /// Judge if exists Driver PhoneNumber 
        /// </summary>
        /// <param name="driverPhoneNumber"></param>
        /// <returns>Taxi-id  if return -1 means fail</returns>
        public ArrayList ExistsDriverPhoneNumber(string driverPhoneNumber)
        {
            return _dDriver.ExistsDriverPhoneNumber(driverPhoneNumber);
        }

        public bool UpdateIMEIByPhoneNumber(string driverPhoneNumber,string IMEI)
        {
           return _dDriver.UpdateIMEIByPhoneNumber(driverPhoneNumber,IMEI);
        }

         public string GetTaxiNoByPhoneNumber(string phoneNumber)
         {
             return _dDriver.GetTaxiNoByPhoneNumber(phoneNumber);
         }

        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public  int GetMaxId()
        {
            return _dDriver.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public  bool Exists(string workid)
        {
            return _dDriver.Exists(workid);
        }

        /// <summary>
        /// 该手机号是否已注册
        /// </summary>
        /// <param name="driverPhoneNumber"></param>
        /// <returns></returns>
        public bool ExistsPhoneNumber(string driverPhoneNumber)
        {
            return _dDriver.ExistsPhoneNumber(driverPhoneNumber);
        }



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public  bool Add(Model.DriverInfo model)
        {
            return _dDriver.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public  bool Update(Model.DriverInfo model)
        {
            return _dDriver.Update(model);
        }
         
        /// <summary>
        /// 得到出租车评分星级
        /// </summary>
        /// <param name="phoneNumber">司机手机号码</param>
        /// <returns></returns>
        public int GetDriverStar(string phoneNumber)
        {
            return _dDriver.GetDriverStar(phoneNumber);
        }

        /// <summary>
        /// 更新出租车评分  
        /// </summary>
        /// <param name="starLevel">评分</param>
        /// <param name="phoneNumber">手机号</param>
        /// <returns></returns>
         public bool UpdateStarLevel(int starLevel, string phoneNumber)
         {
             return _dDriver.UpdateStarLevel(starLevel, phoneNumber);
         }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public  bool Delete(int id)
        {

            return _dDriver.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public  bool DeleteList(string idlist)
        {
            return _dDriver.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public  Model.DriverInfo GetModel(int id)
        {
            return _dDriver.GetModel(id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public  DataSet GetList(string strWhere)
        {
            return _dDriver.GetList(strWhere);
        }

        public DataSet GetList(string parameter, string parameterVaule)
        {
            return _dDriver.GetList(parameter, parameterVaule);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public  List<Model.DriverInfo> GetModelList(string strWhere)
        {
            DataSet ds = _dDriver.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public  List<Model.DriverInfo> DataTableToList(DataTable dt)
        {
            List<Model.DriverInfo> modelList = new List<Model.DriverInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.DriverInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.DriverInfo();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["Gender"] != null && dt.Rows[n]["Gender"].ToString() != "")
                    {
                        model.Gender = dt.Rows[n]["Gender"].ToString();
                    }
                    if (dt.Rows[n]["PhoneNumber"] != null && dt.Rows[n]["PhoneNumber"].ToString() != "")
                    {
                        model.PhoneNumber = dt.Rows[n]["PhoneNumber"].ToString();
                    }
                    if (dt.Rows[n]["WorkId"] != null && dt.Rows[n]["WorkId"].ToString() != "")
                    {
                        model.WorkId = dt.Rows[n]["WorkId"].ToString();
                    }
                    if (dt.Rows[n]["TaxiID"] != null && dt.Rows[n]["TaxiID"].ToString() != "")
                    {
                        model.TaxiID = int.Parse(dt.Rows[n]["TaxiID"].ToString());
                    }
                    if (dt.Rows[n]["Remark"] != null && dt.Rows[n]["Remark"].ToString() != "")
                    {
                        model.Remark = dt.Rows[n]["Remark"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public  DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public  int GetRecordCount(string strWhere)
        {
            return _dDriver.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public  DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return _dDriver.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }


        public bool UpdateSignatureByPhoneNumber(string phoneNumber, string signature)
        {
            return _dDriver.UpdateSignatureByPhoneNumber(phoneNumber, signature);
        }

        #endregion  Method
    }
}
